package com.alpaak.ewell.Singleton;

/**
 * 方式2：双重检验锁
 *
 */
public class Singleton2 {
    private volatile static Singleton2 instance; //声明成 volatile 保证编译器不进行优化
    private Singleton2(){}
 
    public static Singleton2 getSingleton() {
        if (instance == null) {                         
            synchronized (Singleton2.class) {
                if (instance == null) {       
                    instance = new Singleton2();
                }
            }
        }
        return instance;
    }
   
}
